package enemies
{
	import org.flixel.*;
	import org.flixel.plugin.photonstorm.*;
	
	import treasures.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class Exorcist extends Enemy
	{
		public static const WONDERING:uint = 0;
		public static const FOLLOWING:uint = 1;
		
		public function Exorcist(i:uint = 0, j:uint = 0)
		{
			super(i, j);
			
			loadGraphic(Assets.ImgEnemyExorcist, true, false, 25, 25);
			
			addAnimation("UP", [0, 1, 2, 1], 6);
			addAnimation("DOWN", [3, 4, 5, 4], 6);
			addAnimation("LEFT", [6, 7, 8, 7], 6);
			addAnimation("RIGHT", [9, 10, 11, 10], 6);
			addAnimation("DYING", [12, 13, 14, 15], 3, false);
			play("DOWN");
			
			addText("DYING", "UGH!");
			addText("Sees player", "I SEE YOU!");
			
			_speed = 100;
			state = WONDERING;
			
			toggleLight();
		}
		
		override public function update():void
		{
			super.update();
			
			if (!alive)
			{
				return;
			}
			
			if (state == WONDERING)
			{
				if (canSeePlayer(30, false))
				{
					state = FOLLOWING;
					say("Sees player");
					offsetSpeed(50);
					_timer.reset(0);
					return;
				}
				
				if (isIdle)
				{
					if (Player.isAlive)
					{
						if (!goToPoint(Player.midpoint))
						{
							while (!goToRandomTile())
							{
								
							}
						}
					}
					else
					{
						while (!goToRandomTile())
						{
							
						}
					}
				}
			}
			else if (state == FOLLOWING)
			{
				stopAtEdge()
				if (_timer.hasExpired)
				{
					if (canSeePlayer(30, false))
					{
						goToPoint(Player.midpoint);
						_timer.reset(500);
					}
					else if (isIdle)
					{
						state = WONDERING;
						offsetSpeed(-50);
					}
				}
			}
		}
		
		override public function kill():void
		{
			alive = false;
			stopMoving();
			say("DYING");
			play("DYING");
			FlxG.play(Assets.SndFail, Registry.soundVolume);
		}
		
		override public function overlapWithPlayer(p:Player):void
		{
			p.kill();
			FlxG.play(Assets.SndPunch, Registry.soundVolume);
		}
	}
}